/**
 * 
 */
package com.qq.spirit;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.qq.spirit.impl.LoginInter;
import com.qq.spirit.impl.YaowanLogin;
import com.qq.spirit.inter.TaskUnit;
import com.qq.spirit.model.UserData;

/**
 * @author beedoorwei
 * 
 */
public class LoginTask extends TaskUnit
{
	static Map<String, LoginInter> map = new ConcurrentHashMap<String, LoginInter>();
	static
	{
		map.put("yaowan", new YaowanLogin());
	}

	public LoginTask()
	{
	}

	public LoginTask(int gid, TaskUnit a)
	{
		super();
		this.gid = gid;
		this.a = a;
	}

	public void doTask()
	{
		UserData u = GameUserInfoUtil.getUser(gid);
		String dl = u.getGameInfo("game_dl");
		LoginInter login = map.get(dl);
		if (null != login)
		{
			login.doLogin(gid);
			if (u.getUserState() == UserState.LOGIN_GAME)
			{
				TaskManager.addTask(new GetUserInfoTask(gid, a));
			} else
			{
				TaskManager.addTask(this, 60*5);
			}
		}
	}
}
